package com.twu.biblioteca;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

public class UserAccountList {
    ArrayList<UserAccount> userAccountsArrayList;

    public UserAccountList()
    {
        userAccountsArrayList=new ArrayList<UserAccount>();
        addInitialUserAccountToUserAccountList();
    }
    public void addUserAccount(String userName,String password,String name,String emailID,String phoneNumber)
    {
        UserAccount userAccountObject=new UserAccount(userName,password,name,emailID,phoneNumber);
        userAccountsArrayList.add(userAccountObject);
    }
    public void addInitialUserAccountToUserAccountList()
    {
        addUserAccount("111-1111","password1","Rhushikesh Ganesh Apte","rhushikeshapte@yahoo.com","+91-9665764789");
        addUserAccount("111-1112","password2","Vaishav Arun Bachhav","vab@yahoo.com","+91-9665654789");
        addUserAccount("111-1113","password3","Nawanath Gurunath Bade","ngb@yahoo.com","+91-9663214789");
        addUserAccount("111-1114","password4","Mayur Shrikrishna Barge","msb@yahoo.com","+91-9623464789");
        addUserAccount("111-1115","password5","Akshay Yuvaraj Mohite","aym@yahoo.com","+91-9665121678");
    }
    public UserAccount searchValidUserAccount(String userName,String password)
    {
        int loopCounter;
        for(loopCounter=0;loopCounter<userAccountsArrayList.size();loopCounter++)
        {
            if(userAccountsArrayList.get(loopCounter).validateUserAccount(userName,password))
            {
                return userAccountsArrayList.get(loopCounter);
            }
        }
        return null;
    }
    public UserAccount userAccountLoginForm(String userName,String password)
    {
        UserAccount userAccountObject=searchValidUserAccount(userName,password);
        if(userAccountObject==null)
            System.out.println("Your login is failed");
        else
            System.out.println("You are logged successfully");

        return userAccountObject;
    }
}
